class Admin::ProgramsController < ApplicationController

  layout "admin"

  before_filter :find_channel

  def index
    day_of_week = params[:day_of_week] || wday_to_s
    @programs = @channel.programs.where("day_of_week = ?", day_of_week).order("start_time asc")
  end

  def show
    @program = @channel.programs.find(params[:id])
  end

  def new
    @program = Program.new
  end

  def create
    @program = Program.new(params[:program])
    if @program.save
      redirect_to [:admin, @channel, :programs]
    else
      render :action => :new
    end
  end

  def edit
    @program = Program.find(params[:id])
  end

  def update
    @program = Program.find(params[:id])
    if @program.update_attributes(params[:program])
      redirect_to [:admin, @channel, :programs]
    else
      render :action => :edit
    end
  end

  def destroy
    @program = Program.find(params[:id])
    @program.destroy
    redirect_to [:admin, @channel, :programs]
  end


  protected

    def find_channel
      @channel = Channel.find(params[:channel_id])
    end


end
